package com.roc.template.mongo.controller;

import com.roc.template.base.PageBean;
import com.roc.template.mongo.model.User;
import com.roc.template.mongo.service.UserService;
import com.roc.template.mongo.vo.UserVo;
import com.roc.template.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName UserController
 * @Description: TODO
 * @Author Administrator
 * @Date 2020/7/15 17 06
 * @Version V1.0
 **/
@Api(description = "mongo基本操作")
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation("查询分页")
    @GetMapping("/list")
    public Result list(UserVo userVo) {
        PageBean<User> userPageBean = userService.pageQuery(userVo);
        return new Result(true, "","",userPageBean);
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public Result insert(@RequestBody User user) {
        userService.insert(user);
        return new Result(true, "","","");
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable String id) {
        userService.delete(id);
        return new Result(true, "","","");
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public Result update(@RequestBody User user){
        userService.update(user.getId(),user);
        return new Result(true, "","","");
    }

}
